package com.itheima.health.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.health.pojo.OrderSetting;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface OrderSettingMapper extends BaseMapper<OrderSetting> {


    @Select("SELECT ORDERDATE,NUMBER,RESERVATIONS FROM t_ordersetting WHERE ORDERDATE BETWEEN #{beginDate} AND #{endDate}")
    List<OrderSetting> findSettingData(@Param("beginDate") String beginDate, @Param("endDate") String endDate);

    @Update("UPDATE t_ordersetting SET NUMBER = #{number} WHERE ORDERDATE = #{date}")
    void updateNumberByOrderDate(@Param("date") String date, @Param("number")int number);

    @Select("SELECT count(1) FROM t_ordersetting WHERE NUMBER > RESERVATIONS AND ORDERDATE = #{orderDate}")
    int isOrderSettingOK(@Param("orderDate") String orderDate);

    @Update("UPDATE t_ordersetting SET RESERVATIONS = RESERVATIONS + 1 WHERE ORDERDATE = #{orderDate}")
    void updateResetvationSByOrderDate(@Param("orderDate")String orderDate);
}
